<template>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form"
      :defaults.sync="showColumn" :permission="permissionList" :page.sync="page" :before-open="beforeOpen"
      @sortable-change="cloumnSaveOrUpdate" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave"
      @refresh-change="refreshChange" @search-change="searchChange" @search-reset="searchReset"
      @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange" @filter="filterChange"
      @sort-change="sortChange" @row-dblclick="handleRowDBLClick" @on-load="onLoad">

      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" icon="el-icon-document-copy" v-if="permission.database_delete"
          @click="handleCopy(scope.row)">复 制
        </el-button>
        <el-button type="text" size="small" icon="el-icon-document-copy" v-if="permission.database_edit"
          @click.stop="handleOpenColumn(scope.row)">代 码
        </el-button>
        <el-button type="text" size="small" icon="el-icon-s-operation" v-if="permission.database_edit"
          @click.stop="openGenMenu(scope.row)">菜单
        </el-button>
      </template>
      <template slot-scope="scope" slot="menuLeft">
        <div style="float: right;display: flex;">
          <el-button type="danger" size="mini" icon="el-icon-delete" v-if="permission.database_delete"
            @click="handleDelete">删 除
          </el-button>
          <!-- <el-select v-model="value100" placeholder="请选择">
            <el-option v-for="item in options100" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
          <el-button type="primary" size="mini" icon="el-ico-edit" v-if="permission.database_edit"
            @click="handleGen100Config">生成百库百表配置
          </el-button> -->
        </div>
      </template>
      <template slot="menuRight">
        <el-button type="default" @click.stop="exportExcel" icon="el-icon-download" circle size="small"></el-button>
      </template>
    </avue-crud>
    <el-drawer :title="drawerTitle" :visible.sync="drawerDialog" :before-close="handleClose" custom-class="demo-drawer"
      destroy-on-close="true" ref="drawer" direction="rtl" size="100%" @close="closeDrawer">
      <el-divider></el-divider>
      <avue-crud :option="columnOption" :data="columnData" ref="columnCrud" v-model="columnForm"
        :permission="permissionList" :page.sync="columnPage" :before-open="beforeOpen" @row-update="cloumnAddUpdate"
        @row-del="cloumnRowDel" @refresh-change="cloumnRefreshChange" @sortable-change="cloumnSaveOrUpdate"
        @row-click="selectCurrentRow" @selection-change="columnSelectionChange">
        <template slot="menuLeft">
          <el-button @click="cloumnAddRow" icon="el-icon-circle-plus-outline" type="primary" size="small">新增字段
          </el-button>
          <el-button type="primary" size="small" icon="el-icon-save" v-if="permission.database_delete"
            @click="cloumnBatchAdd">批量添加字段
          </el-button>
          <el-button type="primary" size="small" icon="el-icon-save" v-if="permission.database_delete"
            @click="cloumnBatchEdit">批量编辑
          </el-button>
          <el-button type="primary" size="small" icon="el-icon-save" v-if="permission.database_delete"
            @click="cloumnSaveOrUpdate">批量保存
          </el-button>

          <el-button size="small" type="primary" id="copyBtn" @click="openPathDialog"
            data-clipboard-target="#pathText">路径脚本
          </el-button>
          <!-- <el-button size="small" 
                      type="primary" 
                      id="copyBtn" 
                      @click="openPathDialog" 
                      data-clipboard-target="#pathText">ER图
            </el-button> -->
          <el-button type="success" size="small" icon="el-icon-plus" v-if="permission.database_delete"
            @click="generatorIndexSQL()">添加索引
          </el-button>
          <!-- <el-button type="warning"
                      size="small"
                      icon="el-icon-edit"
                      v-if="permission.database_delete"
                      @click="generatorPGSQL()">生成PGSQL
            </el-button> -->

          <el-button type="warning" size="small" icon="el-icon-edit" v-if="permission.database_delete"
            @click="generatorSQL()">生成MYSQL
          </el-button>

          <el-button type="warning" size="small" icon="el-icon-edit" v-if="permission.database_delete"
            @click="generatorAddSQL()">生成添加字段SQL
          </el-button>
          <el-button type="warning" size="small" icon="el-icon-edit" v-if="permission.database_delete"
            @click="generatorUpdateSQL()">生成修改字段SQL
          </el-button>
          <el-button type="warning" size="small" icon="el-icon-edit" v-if="permission.database_delete"
            @click="generatorAddEntity()">生成添加字段实体
          </el-button>
          <el-button type="warning" size="small" icon="el-icon-edit" v-if="permission.database_delete"
            @click="handleGenerator()">生成管理代码
          </el-button>

        </template>

      </avue-crud>
      <div class="el-drawer__footer">
        <el-button size="small" icon="el-icon-close" @click="cancelDrawer">取 消</el-button>
      </div>
    </el-drawer>
    <!-- 
      生成菜单对话框
     -->
    <el-dialog title="生成菜单" width="70%" :close-on-click-modal='false' @close="menuDialog = false"
      :visible.sync="menuDialog">
      <avue-form ref="menuForm" v-model="menuForm" :option="menuOption" @submit="handleAddMenu">
      </avue-form>
    </el-dialog>
    <!-- 
      sql代码对话框
     -->
    <el-dialog title="SQL预览" width="70%" :visible.sync="sqlDialogVisible">
      <el-input id="sqlText" type="textarea" :autosize="{ minRows: 5, maxRows: 20 }" readonly='true' v-model="sqlText">
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="success" @click="generator100SQL($event)"
          data-clipboard-target="#sqlText">生成100表SQL</el-button>
        <el-button size="small" type="primary" id="copyBtn" @click="copyClipboard($event)"
          data-clipboard-target="#sqlText">复制SQL</el-button>
        <el-button size="small" type="primary" @click="sqlDialogVisible = false">创建表</el-button>
        <el-button size="small" @click="sqlDialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 
      百库百表配置对话框
     -->
    <el-dialog title="百库百表配置" width="70%" :visible.sync="configDialogVisible">

      <div style="display: flex; padding: 10px 0px;">
        当前数据库链接地址：
        <el-input style="width: 500px;" placeholder="请输入内容" v-model="databaseLinkAddress">
        </el-input>
      </div>
      <el-input id="configText" type="textarea" :autosize="{ minRows: 5, maxRows: 20 }" readonly='true'
        v-model="configText">
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="generator100KUSQL($event)"
          data-clipboard-target="#sqlText">创建百库SQL</el-button>
        <el-button size="small" type="info" @click="delete100KUSQL($event)"
          data-clipboard-target="#sqlText">删除百库SQL</el-button>
        <el-button size="small" type="success" @click="handleGen1Config($event)"
          data-clipboard-target="#sqlText">生成单库配置</el-button>
        <el-button size="small" type="success" @click="handleGen100Config($event)"
          data-clipboard-target="#sqlText">生成100库配置</el-button>
        <el-button size="small" type="primary" id="copyBtn" @click="copyClipboard100Config($event)"
          data-clipboard-target="#sqlText">复制SQL</el-button>
        <el-button size="small" @click="configDialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 
      添加索引对话框
     -->
    <el-dialog title="SQL预览" width="70%" :visible.sync="indexDailog">
      <avue-form :option="indexOption" v-model="indexForm">
      </avue-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click='updateIndexColumn'
          data-clipboard-target="#pathText">确定</el-button>
        <el-button size="small" @click="indexDailog = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 
      添加TCC属性对话框
     -->
    <el-dialog title="SQL预览" width="70%" :visible.sync="tccDailog">
      <avue-form :option="tccOption" v-model="tccForm">
      </avue-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click='updateTccColumn'
          data-clipboard-target="#pathText">确定</el-button>
        <el-button size="small" @click="tccDailog = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 
      路径对话框
     -->
    <el-dialog title="创建路径脚本预览" :visible.sync="pathDialog">
      <el-input id="pathText" type="textarea" :autosize="{ minRows: 5, maxRows: 20 }" readonly='true' v-model="pathText">
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click="copyClipboardPath($event)"
          data-clipboard-target="#pathText">复制脚本</el-button>
        <el-button size="small" @click="pathDialog = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 
      批量添加数据对话框
     -->
    <el-dialog title="变量标准化" width='70%' top="6vh" :close-on-click-modal='false' :visible.sync="batchAddColumnDialog"
      destroy-on-close='true' center>
      <el-row>
        <el-col :span="6">
          <el-input type="textarea" :autosize="{ minRows: 20, maxRows: 20 }" placeholder="可直接从excel粘贴中文变量"
            v-model="importDataArea" @change='handleImport'>
          </el-input>
        </el-col>
        <el-col :span="1">
        </el-col>
        <el-col :span="17">
          <el-table :data="allFieldData" height="430" border v-loading="tabLoading" :row-class-name="tableRowClassName"
            style="width: 100%">
            <el-table-column prop="oldColumnComment" label="字段中文" width="150">
            </el-table-column>
            <el-table-column prop="columnName" label="字段名字" width="200">
            </el-table-column>
            <el-table-column prop="dataTypeFmt" label="数据类型" width="200">
            </el-table-column>
            <el-table-column prop="columnFullName" label="全名">
            </el-table-column>
            <el-table-column fixed="right" label="状态操作" width="120">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.foundFlag == 'root' || scope.row.foundFlag == 'find'" size="small">需加变量库</el-tag>
                <el-tag v-if="scope.row.foundFlag == 'field'">已在变量库</el-tag>
                <el-tag v-if="scope.row.foundFlag == 'lostRoot'" type="warning">缺失词根</el-tag>
                <el-tag v-if="scope.row.foundFlag == 'lostAttrRoot'" type="danger">缺失定语&词根</el-tag>
                <el-tag v-if="scope.row.foundFlag == 'lostAttr'" type="success">缺失定语</el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click="handleImport">标准化</el-button>
        <el-button size="small" type="primary" id="copyBtn" :disabled="allFieldData.length == 0"
          @click="handleBatchImport($event)">批量添加字段</el-button>
        <el-button size="small" @click="batchAddColumnDialog = false">取 消</el-button>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
import { autoGetSysToolDictFieldList } from '@/api/tool/sysToolDictFieldApi';
import { querySysMenuTreeByUserId, querySysButtonByUserId, querySysMenuTree, exportSysMenuExcel, saveOrUpdateSysMenu, saveOrUpdateSysMenuList, saveSysMenu, saveSysMenuList, deleteSysMenu, querySysMenu, querySysMenuListPage, updateSysMenu, deleteSysMenuList } from '@/api/system/sysMenuApi';
import { exportSysToolColumnsExcel, saveOrUpdateSysToolColumns, saveOrUpdateSysToolColumnsList, saveSysToolColumns, deleteSysToolColumns, querySysToolColumns, querySysToolColumnsListPage, updateSysToolColumns, deleteSysToolColumnsList } from '@/api/tool/sysToolColumnsApi';
import { generatorCode, exportSysToolTablesExcel, saveSysToolTables, deleteSysToolTables, querySysToolTables, querySysToolTablesListPage, updateSysToolTables, deleteSysToolTablesList } from '@/api/tool/sysToolTablesApi';
import { mapGetters } from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import { genPGSQL, genSQL, gen100SQL, genIndexSQL, genAddColumnSQL, genUpdateColumnSQL, genAddColumnEntity } from '@/util/genSQL';
import { filterFormat, copyToClipboard } from '@/util/util';
export default {
  data() {
    return {
      //生成100配置选择
      options100: [],
      value100: '',
      configText: '',
      configDialogVisible: false,
      databaseLinkAddress: '',
      linkAddress: [],
      //菜单生成
      menuDialog: false,


      drawerTitle: '数据表定义',
      drawerDialog: false,
      sqlDialogVisible: false,
      pathDialog: false,
      tccDailog: false,
      sqlText: '',
      pathText: '',
      form: {},
      selectionList: [],
      loading: true,
      showColumn: [],
      option: {
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 120,
        dialogTop: '50px',
        indexFixed: true,
        stripe: true,
        //height: 'auto',
        calcHeight: 120,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        selection: true,
        addBtn: true,
        viewBtn: true,
        cancelBtn: true,
        delBtn: false,
        printBtn: false,
        saveBtn: true,
        filterBtn: true,
        menuWidth: 320,
        dialogMenuPosition: 'center',
        dialogDirection: 'rtl',
        dialogType: 'dialog',
        dialogFullscreen: false,
        dialogClickModal: false,
        dialogWidth: '70%',
        highlightCurrentRow: true,
        column: [
          {
            label: '所属系统',
            prop: 'tableCatalog',
            type: 'select',
            value: 'common',
            rules: [{
              required: true,
              message: '请选择所属系统',
              trigger: 'blur'
            }],
            dicData: [
              {
                label: '公共平台',
                value: 'common'
              }, {
                label: '分布式核心',
                value: 'corebank'
              }, {
                label: '雅典娜',
                value: 'athena'
              }]
          },
          {
            label: '表类型',
            prop: 'tableType',
            type: 'select',
            search: true,
            searchMmultiple: true,
            searchFilterable: true,
            value: 'sys',
            rules: [{
              required: true,
              message: '请选择表类型',
              trigger: 'blur'
            }],
            dicData: [
              {
                label: '业务表',
                value: 'biz'
              }, {
                label: '系统表',
                value: 'sys'
              }, {
                label: '工具表',
                value: 'tool'
              }]
          },
          {
            label: '数据库',
            prop: 'tableSchema',
            search: true,
            type: 'select',
            search: true,
            sortable: true,
            value: 'D001',
            width: '100',
            rules: [{
              required: true,
              message: '请选择表类型',
              trigger: 'blur'
            }],
            dicData: [
            ]
          },
          {
            label: '表名',
            prop: 'tableName',
            sortable: true,

            //filterMultiple: true,
            width: 180,
            rules: [{
              required: false,
              message: '请输入表名',
              trigger: 'blur'
            }]
          },

          {
            label: '主键',
            prop: 'primaryKey',
            rules: [{
              required: true,
              message: '请输入主键名',
              trigger: 'blur'
            }]
          },
          {
            label: '菜单编号',
            prop: 'menuNo',
            width: 180,
            rules: [{
              required: false,
              message: '请输入主键名',
              trigger: 'blur'
            }]
          },
          {
            label: '表说明',
            prop: 'tableComment',
            search: true,
            filterable: true,
            minWidth: 200,
            span: 24
          },
        ],
        group: [
          {
            label: '工程信息',
            icon: 'el-icon-info',
            prop: '1587820852668_22220',
            column: [
              {
                label: '模块名英文',
                prop: 'moduleName',
                value: 'serviceName',
                rules: [{
                  required: true,
                  message: '请输入模块名英文',
                  trigger: 'blur'
                }]
              },
              {
                label: '服务名中文',
                prop: 'serviceName',
                rules: [{
                  required: true,
                  message: '请输入服务名中文',
                  trigger: 'blur'
                }]
              },
              {
                label: '工程名',
                prop: 'projectName',
                span: 24,
                rules: [{
                  required: true,
                  message: '请输入工程名',
                  trigger: 'blur'
                }]
              },
              {
                label: '后端包名',
                prop: 'packageName',
                rules: [{
                  required: true,
                  message: '请输入后端包名',
                  trigger: 'blur'
                }]
              },
              {
                label: '前后端标志',
                prop: 'backFrontFlag',
                type: 'radio',
                value: '0',
                dicData: [
                  {
                    label: '前后+后端',
                    value: '0'
                  }, {
                    label: '前端',
                    value: '1'
                  }, {
                    label: '后端',
                    value: '2'
                  }],
                rules: [{
                  required: true,
                  message: '请选择前后端标志',
                  trigger: 'blur'
                }]
              },
              {
                label: '后端路径',
                prop: 'backendPath',
                span: 24,
                rules: [{
                  required: true,
                  message: '请输入后端路径',
                  trigger: 'blur'
                }]
              },
              {
                label: '前端路径',
                prop: 'frontendPath',
                span: 24,
                rules: [{
                  required: true,
                  message: '请输入表前缀',
                  trigger: 'blur'
                }]
              },
            ]
          }
        ]
      },

      //菜单
      menuForm: {},
      menuOption: {
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 120,
        dialogTop: '50px',
        indexFixed: true,
        stripe: true,
        calcHeight: 80,
        searchMenuSpan: 6,
        tip: false,
        lazy: true,
        rowKey: 'id',
        border: true,
        index: true,
        selection: true,
        addBtn: true,
        viewBtn: true,
        delBtn: true,
        cancelBtn: true,
        printBtn: false,
        saveBtn: true,
        filterBtn: true,
        menuWidth: 280,
        dialogMenuPosition: 'center',
        dialogDirection: 'rtl',
        dialogType: 'dialog',
        dialogFullscreen: false,
        dialogClickModal: false,
        dialogWidth: '70%',
        highlightCurrentRow: true,
        searchShow: true,
        sortable: false,
        column: [
          {
            label: '上级菜单ID',
            prop: 'parentMenuId',
            dicFlag: true,
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            overHidden: true,
            rules: [{
              required: true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            props: {
              label: 'name',
              value: 'id'
            },
            // tpyeformat(item, label, value) {
            //   return `值:${item[label]}-名:${item[value]}`
            // },
            type: 'tree',
            dicData: [],
          },
          {
            label: '菜单名称',
            prop: 'menuName',
            type: 'input',
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            width: 200,
            rules: [{
              required: true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData: []
          },
          {
            label: '路由地址',
            prop: 'routeAddress',
            type: 'input',
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            overHidden: true,
            rules: [{
              required: true,
              message: '请输入内容',
              trigger: 'blur'
            }],
            dicData: []
          },
          {
            label: '菜单图标',
            prop: 'menuIcon',
            width: 0,
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            overHidden: true,
            rules: [{
              required: false,
              message: '请输入内容',
              trigger: 'blur'
            }],
            type: 'icon',
            iconList: [{
              label: '基本图标',
              list: ['el-icon-platform-eleme ', 'el-icon-eleme', 'el-icon-delete-solid', 'el-icon-delete', 'el-icon-s-tools', 'el-icon-setting', 'el-icon-user-solid', 'el-icon-user', 'el-icon-phone', 'el-icon-phone-outline', 'el-icon-more', 'el-icon-more-outline', 'el-icon-star-on', 'el-icon-star-off', 'el-icon-s-goods', 'el-icon-goods', 'el-icon-warning', 'el-icon-warning-outline', 'el-icon-question', 'el-icon-info', 'el-icon-remove', 'el-icon-circle-plus', 'el-icon-success', 'el-icon-error', 'el-icon-zoom-in', 'el-icon-zoom-out', 'el-icon-remove-outline', 'el-icon-circle-plus-outline', 'el-icon-circle-check', 'el-icon-circle-close', 'el-icon-s-help', 'el-icon-help', 'el-icon-minus', 'el-icon-plus', 'el-icon-check', 'el-icon-close', 'el-icon-picture', 'el-icon-picture-outline', 'el-icon-picture-outline-round', 'el-icon-upload', 'el-icon-upload2', 'el-icon-download', 'el-icon-camera-solid', 'el-icon-camera', 'el-icon-video-camera-solid', 'el-icon-video-camera', 'el-icon-message-solid', 'el-icon-bell', 'el-icon-s-cooperation', 'el-icon-s-order', 'el-icon-s-platform', 'el-icon-s-fold', 'el-icon-s-unfold', 'el-icon-s-operation', 'el-icon-s-promotion', 'el-icon-s-home', 'el-icon-s-release', 'el-icon-s-ticket', 'el-icon-s-management', 'el-icon-s-open', 'el-icon-s-shop', 'el-icon-s-marketing', 'el-icon-s-flag', 'el-icon-s-comment', 'el-icon-s-finance', 'el-icon-s-claim', 'el-icon-s-custom', 'el-icon-s-opportunity', 'el-icon-s-data', 'el-icon-s-check', 'el-icon-s-grid', 'el-icon-menu', 'el-icon-share', 'el-icon-d-caret', 'el-icon-caret-left', 'el-icon-caret-right', 'el-icon-caret-bottom', 'el-icon-caret-top', 'el-icon-bottom-left', 'el-icon-bottom-right', 'el-icon-back', 'el-icon-right', 'el-icon-bottom', 'el-icon-top', 'el-icon-top-left', 'el-icon-top-right', 'el-icon-arrow-left', 'el-icon-arrow-right', 'el-icon-arrow-down', 'el-icon-arrow-up', 'el-icon-d-arrow-left', 'el-icon-d-arrow-right', 'el-icon-video-pause', 'el-icon-video-play', 'el-icon-refresh', 'el-icon-refresh-right', 'el-icon-refresh-left', 'el-icon-finished', 'el-icon-sort', 'el-icon-sort-up', 'el-icon-sort-down', 'el-icon-rank', 'el-icon-loading', 'el-icon-view', 'el-icon-c-scale-to-original', 'el-icon-date', 'el-icon-edit', 'el-icon-edit-outline', 'el-icon-folder', 'el-icon-folder-opened', 'el-icon-folder-add', 'el-icon-folder-remove', 'el-icon-folder-delete', 'el-icon-folder-checked', 'el-icon-tickets', 'el-icon-document-remove', 'el-icon-document-delete', 'el-icon-document-copy', 'el-icon-document-checked', 'el-icon-document', 'el-icon-document-add', 'el-icon-printer', 'el-icon-paperclip', 'el-icon-takeaway-box', 'el-icon-search', 'el-icon-monitor', 'el-icon-attract', 'el-icon-mobile', 'el-icon-scissors', 'el-icon-umbrella', 'el-icon-headset', 'el-icon-brush', 'el-icon-mouse', 'el-icon-coordinate', 'el-icon-magic-stick', 'el-icon-reading', 'el-icon-data-line', 'el-icon-data-board', 'el-icon-pie-chart', 'el-icon-data-analysis', 'el-icon-collection-tag', 'el-icon-film', 'el-icon-suitcase', 'el-icon-suitcase-1', 'el-icon-receiving', 'el-icon-collection', 'el-icon-files', 'el-icon-notebook-1', 'el-icon-notebook-2', 'el-icon-toilet-paper', 'el-icon-office-building', 'el-icon-school', 'el-icon-table-lamp', 'el-icon-house', 'el-icon-no-smoking', 'el-icon-smoking', 'el-icon-shopping-cart-full', 'el-icon-shopping-cart-1', 'el-icon-shopping-cart-2', 'el-icon-shopping-bag-1', 'el-icon-shopping-bag-2', 'el-icon-sold-out', 'el-icon-sell', 'el-icon-present', 'el-icon-box', 'el-icon-bank-card', 'el-icon-money', 'el-icon-coin', 'el-icon-wallet', 'el-icon-discount', 'el-icon-price-tag', 'el-icon-news', 'el-icon-guide', 'el-icon-male', 'el-icon-female', 'el-icon-thumb', 'el-icon-cpu', 'el-icon-link', 'el-icon-connection', 'el-icon-open', 'el-icon-turn-off', 'el-icon-set-up', 'el-icon-chat-round', 'el-icon-chat-line-round', 'el-icon-chat-square', 'el-icon-chat-dot-round', 'el-icon-chat-dot-square', 'el-icon-chat-line-square', 'el-icon-message', 'el-icon-postcard', 'el-icon-position', 'el-icon-turn-off-microphone', 'el-icon-microphone', 'el-icon-close-notification', 'el-icon-bangzhu', 'el-icon-time', 'el-icon-odometer', 'el-icon-crop', 'el-icon-aim', 'el-icon-switch-button', 'el-icon-full-screen', 'el-icon-copy-document', 'el-icon-mic', 'el-icon-stopwatch', 'el-icon-medal-1', 'el-icon-medal', 'el-icon-trophy', 'el-icon-trophy-1', 'el-icon-first-aid-kit', 'el-icon-discover', 'el-icon-place', 'el-icon-location', 'el-icon-location-outline', 'el-icon-location-information', 'el-icon-add-location', 'el-icon-delete-location', 'el-icon-map-location', 'el-icon-alarm-clock', 'el-icon-timer', 'el-icon-watch-1', 'el-icon-watch', 'el-icon-lock', 'el-icon-unlock', 'el-icon-key', 'el-icon-service', 'el-icon-mobile-phone', 'el-icon-bicycle', 'el-icon-truck', 'el-icon-ship', 'el-icon-basketball', 'el-icon-football', 'el-icon-soccer', 'el-icon-baseball', 'el-icon-wind-power', 'el-icon-light-rain', 'el-icon-lightning', 'el-icon-heavy-rain', 'el-icon-sunrise', 'el-icon-sunrise-1', 'el-icon-sunset', 'el-icon-sunny', 'el-icon-cloudy', 'el-icon-partly-cloudy', 'el-icon-cloudy-and-sunny', 'el-icon-moon', 'el-icon-moon-night', 'el-icon-dish', 'el-icon-dish-1', 'el-icon-food', 'el-icon-chicken', 'el-icon-fork-spoon', 'el-icon-knife-fork', 'el-icon-burger', 'el-icon-tableware', 'el-icon-sugar', 'el-icon-dessert', 'el-icon-ice-cream', 'el-icon-hot-water', 'el-icon-water-cup', 'el-icon-coffee-cup', 'el-icon-cold-drink', 'el-icon-goblet', 'el-icon-goblet-full', 'el-icon-goblet-square', 'el-icon-goblet-square-full', 'el-icon-refrigerator', 'el-icon-grape', 'el-icon-watermelon', 'el-icon-cherry', 'el-icon-apple', 'el-icon-pear', 'el-icon-orange', 'el-icon-coffee', 'el-icon-ice-tea', 'el-icon-ice-drink', 'el-icon-milk-tea', 'el-icon-potato-strips', 'el-icon-lollipop', 'el-icon-ice-cream-square', 'el-icon-ice-cream-roun']
            }, {
              label: '方向图标',
              list: ['el-icon-back', 'el-icon-arrow-left', 'el-icon-arrow-down', 'el-icon-arrow-right', 'el-icon-arrow-up']
            }, {
              label: '阿里云图标',
              list: ['iconfont icon-zhongyingwen', 'iconfont icon-rizhi1', 'iconfont icon-bug', 'iconfont icon-qq1', 'iconfont icon-weixin1']
            }
            ]
          }
        ]
      },

      data: [],

      // 表字段定义区
      columnSelectionList: [],
      allFieldData: [],
      tabLoading: false,
      importDataArea: 'ID\n客户号\n租户ID',
      batchAddColumnDialog: false,
      currentFieldRow: {},
      columnForm: {},
      columnOption: {
        keyId: 'id',
        menuWidth: 150,
        height: 500,
        addBtn: false,
        editBtn: true,
        addRowBtn: false,
        cellBtn: true,
        sortable: true,
        indexFixed: true,
        index: true,
        border: true,
        highlightCurrentRow: true,
        stripe: true,
        selection: true,

        column: [
          {
            label: '表名',
            minWidth: 150,
            prop: 'tableName'
          },
          {
            label: '字段中文名',
            width: 180,
            cell: true,
            prop: 'columnComment',
            type: 'input',
            remote: true,
            // props: {
            //   label: 'columnComment',
            //   value: 'columnName'
            // },
            // dicMethod:'get',
            // dicUrl: '/tool/sysToolDictField/querySysToolDictFieldListPage?columnComment={{key}}&tenantId=D001', //+localStorage.getItem('loglevel:webpack-dev-server'),
            // change: ({value,column}) => {
            //   this.columnSelected(value,column);
            // }, 
            rules: [
              {
                required: true,
                message: '请选择中文名',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '字段变量名',
            prop: 'columnName',
            type: 'input',
            minWidth: 150,
            cell: true,
          }, {
            label: '数据类型',
            prop: 'dataType',
            type: 'select',
            cell: true,
            width: 120,
            dicData: [{
              label: 'varchar',
              value: 'varchar'
            }, {
              label: 'int2',
              value: 'int2'
            }, {
              label: 'int4',
              value: 'int4'
            }, {
              label: 'int8',
              value: 'int8'
            }, {
              label: 'char',
              value: 'char'
            }, {
              label: 'decimal',
              value: 'decimal'
            }, {
              label: 'datetime',
              value: 'datetime'
            }, {
              label: 'text',
              value: 'text'
            }]
          }, {
            label: '数据长度',
            cell: true,
            width: 120,
            prop: 'length'
          }, {
            label: '小数长度',
            cell: true,
            width: 120,
            prop: 'decimalLength'
          }, {
            label: '是否Key',
            prop: 'columnKey',
            type: 'switch',
            value: 'false',
            cell: true
          }, {
            label: '是否加密',
            prop: 'fmkdir',
            type: 'radio',
            width: 120,
            value: '0',
            cell: true,
            dicData: [{
              label: '否',
              value: '0'
            }, {
              label: '是',
              value: '1'
            }]
          }, {
            label: '默认值',
            width: 150,
            cell: true,
            prop: 'value'
          }, {
            label: '是否不为空',
            prop: 'nullable',
            type: 'switch',
            width: 100,
            value: 'true',
            cell: true
          }, {
            label: '控件类型',
            prop: 'type',
            type: 'select',
            cell: true,
            width: 120,
            dicData: [{
              label: '输入框',
              value: 'input'
            }, {
              label: '选择框',
              value: 'select'
            }, {
              label: '树形框',
              value: 'tree'
            }, {
              label: '单选框',
              value: 'radio'
            }, {
              label: '复选框',
              value: 'checkbox'
            }, {
              label: '日期',
              value: 'date'
            }],
          }, {
            label: '宽度(width)',
            prop: 'width',
            type: 'input',
            width: 100,
            value: 40,
            cell: true
          }, {
            label: '列宽度(span)',
            prop: 'span',
            type: 'input',
            width: 100,
            value: 12,
            cell: true
          }, {
            label: '搜索文本宽度',
            prop: 'searchLabelWidth',
            type: 'input',
            width: 100,
            value: 80,
            cell: true
          }, {
            label: '是否搜索',
            prop: 'search',
            type: 'switch',
            cell: true
          }, {
            label: '搜索多选',
            prop: 'searchMultiple',
            type: 'switch',
            cell: true
          }, {
            label: '是否多选',
            prop: 'multiple',
            type: 'switch',
            cell: true
          }, {
            label: '是否排序',
            prop: 'sortable',
            type: 'switch',
            cell: true
          }, {
            label: '表单显示',
            prop: 'showInForm',
            type: 'switch',
            cell: true
          }, {
            label: '导出excel',
            prop: 'excel',
            type: 'switch',
            cell: true
          }, {
            label: '是否隐藏',
            prop: 'hide',
            type: 'switch',
            cell: true
          }, {
            label: '超出隐藏',
            prop: 'overHidden',
            type: 'switch',
            cell: true
          }, {
            label: '是否必输',
            prop: 'required',
            type: 'switch',
            cell: true
          }, {
            label: '必输提示',
            prop: 'message',
            type: 'input',
            width: 150,
            cell: true
          }]
      },
      columnData: [],


      //索引
      indexForm: [],
      indexDailog: false,
      indexOption: {
        labelWidth: 110,
        saveBtn: false,
        submitBtn: false,
        clearBtn: false,
        cancelBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '添加索引',
            prop: 'index1',
            type: 'dynamic',
            span: 24,
            children: {
              align: 'center',
              headerAlign: 'center',
              column: [
                {
                  width: 150,
                  label: '唯一索引',
                  prop: 'uniIndx',
                  type: 'radio',
                  value: '0',
                  dicData: [{
                    label: '否',
                    value: '0'
                  }, {
                    label: '是',
                    value: '1'
                  }]
                },
                {
                  label: '选择字段',
                  prop: 'columnName',
                  type: 'select',
                  filterable: true,
                  multiple: true,
                  dicData: []
                }]
            }
          },

        ]
      },

      // tcc属性
      tccForm: {},
      tccOption: {
        labelWidth: 110,
        saveBtn: false,
        submitBtn: false,
        clearBtn: false,
        cancelBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '冻结/可达字段',
            prop: 'tccFreezeColumn',
            type: 'select',
            filterable: true,
            rules: [{
              required: true,
              message: '请选择字段',
              trigger: 'blur'
            }],
            dicData: []
          },
          {
            label: '入账字段',
            prop: 'tccPostColumn',
            type: 'select',
            filterable: true,
            rules: [{
              required: true,
              message: '请选择字段',
              trigger: 'blur'
            }],
            dicData: []
          },
          {
            label: '选择条件字段',
            prop: 'tccIndex',
            type: 'select',
            filterable: true,
            span: 24,
            multiple: true,
            dicData: []
          }]
      },
      // 请求参数区
      reqParams: {
        head: {
          transCode: ''
        },
        singleBody: {},
        listBody: [{}],
        sqlCondition: [],
        orderRule: [],
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {},
      currentRow: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      columnPage: {
        pageSize: 100,
        currentPage: 1,
        total: 0
      }
    };
  },
  computed: {
    ...mapGetters(['permission', 'userInfo']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.database_add, false),
        viewBtn: this.vaildData(this.permission.database_view, false),
        delBtn: this.vaildData(this.permission.database_delete, false),
        editBtn: this.vaildData(this.permission.database_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push({ id: ele.id });
      });
      return ids;
    }
  },
  methods: {
    /**
     * 生成菜单
     */
    openGenMenu(row) {
      this.currentRow = row;
      this.menuDialog = true;
      this.menuForm.menuName = row.tableComment;
      this.menuForm.menuNo = row.tableName;
      this.menuForm.menuNickName = 'menu';
      this.menuForm.menuCategory = '1';
      this.menuForm.menuSeq = '0';
      this.menuForm.keepAliveFlag = '1';
      this.menuForm.menuLevel = '1';
      this.menuForm.validFlag = '1';
      this.menuForm.projectControlFlag = '0';
      this.menuForm.routeAddress = '/' + row.moduleName + '/' + this.$toolUtil.toHump(row.tableName);
    },
    /**
     * 添加菜单
     */
    handleAddMenu(form, done) {
      this.reqParams = {
        singleBody: {
          menuNo: this.currentRow.menuNo
        },
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1,
        pageSize: 99999
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysMenuListPage(this.commonData).then(res => {
        const data = res.data.body.listBody;
        if (data.length == 0) {
          this.addMenu(done);
        }
        else {
          done();
          this.$message({
            customClass: 'zZindex',
            type: 'error',
            message: '该表名的菜单编号已存在!'
          });
        }
      }, error => {
        this.loading = false;
      });
    },
    addMenu(done) {
      //1、添加主菜单，获取主ID
      this.reqParams.singleBody = this.menuForm;
      this.commonData = reqCommonMsg(this.reqParams)
      saveSysMenu(this.commonData).then(res => {
        this.menuForm = res.data.body.singleBody;
        console.log('this.menuForm ==', this.menuForm);
        this.addSubMenu(done);
        this.getMenuTree();
      }, error => {
        //this.$console.log(error);
        loading();
      });
    },
    addSubMenu(done) {
      //组装子菜单
      let menuList = [];
      let subMenuName = ['新增', '删除', '修改', '查看', '批量新增', '批量删除', '下载', '保存', '搜索', '双击'];
      let subMenuNo = ['add', 'delete', 'edit', 'view', 'batch_add', 'batch_delete', 'download', 'save', 'search', 'dbclick'];
      let subMenuIcon = ['el-icon-plus', 'el-icon-delete', 'el-icon-view', 'el-icon-edit', 'el-icon-plus', 'el-icon-delete', 'el-icon-bottom', 'el-icon-document-checked', 'el-icon-search', 'el-icon-finished'];
      subMenuName.forEach((element, index) => {
        menuList.push({
          parentMenuId: this.menuForm.id,
          menuIcon: subMenuIcon[index],
          menuName: subMenuName[index],
          menuNo: this.menuForm.menuNo + '_' + subMenuNo[index],
          menuNickName: subMenuNo[index],
          menuCategory: '2',
          menuSeq: index + 1,
          keepAliveFlag: this.menuForm.keepAliveFlag,
          menuLevel: this.menuForm.menuLevel,
          validFlag: this.menuForm.validFlag,
          projectControlFlag: this.menuForm.projectControlFlag,
          routeAddress: this.menuForm.routeAddress + '/' + subMenuNo[index],
          parentMenuName: this.menuForm.menuName
        });
      });

      this.reqParams.singleBody = {};
      this.reqParams.listBody = menuList;
      this.commonData = reqCommonMsg(this.reqParams)
      saveSysMenuList(this.commonData).then(res => {
        done();
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '操作成功!'
        });
        this.menuDialog = false;
      }, error => {
        //this.$console.log(error);
        loading();
      });
    },
    //加载列表数据
    onLoad(page) {
      this.loading = true;
      this.reqParams = {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: page.currentPage,
        pageSize: page.pageSize
      }
      //console1.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      querySysToolTablesListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.page.total = data.total;
        this.data = data.listBody;
        this.data.forEach((item, index) => {
          if (item.index1 != '') {
            this.data[index].index1 = JSON.parse(item.index1);
          }
        });
        this.loading = false;
        this.selectionClear();
      }, error => {
        this.loading = false;
      });
    },
    /**
     * 100库配置-查询数据库
     */
    handleGen100Config() {
      if (!this.value100) {
        this.$message({
          customClass: 'zZindex',
          type: 'info',
          message: '请选择库!'
        });
        return false
      }
      this.linkAddress.forEach(element => {
        if (element.label == this.value100) {
          this.databaseLinkAddress = element.value;
        }
      });

      this.reqParams = {
        singleBody: {
          tableSchema: this.value100
        },
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1,
        pageSize: 1000
      }
      //console1.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      querySysToolTablesListPage(this.commonData).then(res => {
        this.configDialogVisible = true;
        this.configText = '';
        this.gen100Config(res.data.body.listBody);
      }, error => {
        this.loading = false;
      });
    },


    gen100Config(list) {
      var headText = 'spring.shardingsphere.datasource.names=';
      //生成百库配置 this.value100
      var id = 0;
      var tableCnt = 100;
      for (var i = 0; i < tableCnt; i++) {
        var index = i;
        id = i;
        if (i < tableCnt - 1) {
          headText += 'master' + index + ',';
        }
        else {
          headText += 'master' + index + '\n';
        }
        this.configText += '#master' + index + '\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.type=com.alibaba.druid.pool.DruidDataSource\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.driver-class-name=com.mysql.cj.jdbc.Driver\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.url=jdbc:mysql://' + this.databaseLinkAddress + '/' + this.value100 + '_' + index + '?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&verifyServerCertificate=false&autoReconnct=true&autoReconnectForPools=true&useInformationSchema=true&allowMultiQueries=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.username=ENC(9tgLVt3eYub3lxf2MN/yAA==)\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.password=ENC(M+7CDg0t6CEEnFfFZCQaX2LuTFecjf8x)\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.initial-size=10\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.min-idle=10\n';
        this.configText += '#spring.shardingsphere.datasource.master' + index + '.max-idle=1000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.max-active=1000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.max-wait=30000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.timeBetweenEvictionRunsMillis=60000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.minEvictableIdleTimeMillis=300000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.validationQuery=SELECT 1 FROM DUAL\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.testWhileIdle=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.testOnBorrow=false\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.testOnReturn=false\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.poolPreparedStatements=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.maxPoolPreparedStatementPerConnectionSize=20\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.filters=stat,wall,log4j\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.connectionProperties=druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.web-stat-filter.enabled=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.web-stat-filter.url-pattern=/*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.deny=192.168.1.73\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.reset-enable=false\n';
        this.configText += '# 合并多个DruidDataSource的监控数据\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.useGlobalDataSourceStat=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.logSlowSql=true\n';
        this.configText += '#以下4项，将来上生产环境以后一定要改！！！！！一定要改！！！！！一定要改！！！！！\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.url-pattern=/druid/*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.allow=127.0.0.1,*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.login-username=admin\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.login-password=admin123\n';
        this.configText += '\n';
        this.configText += '# 读写分离 master' + index + ' 参数\n';
        this.configText += 'spring.shardingsphere.sharding.master-slave-rules.' + this.value100 + '_' + index + '.master-data-source-name=master' + index + '\n';
        this.configText += 'spring.shardingsphere.sharding.master-slave-rules.' + this.value100 + '_' + index + '.slave-data-source-names=master' + index + '\n';
        this.configText += '\n';
      }
      this.configText += '# 打印执行的数据库以及语句\n';
      this.configText += 'spring.shardingsphere.props.sql.show = true\n';
      this.configText += 'spring.main.allow-bean-definition-overriding=true\n';
      this.configText += '\n';

      this.configText += '# #shardingjdbc解析上下文和改写后的SQL\n';
      this.configText += 'spring.shardingsphere.props.sql.show=false**\n';
      this.configText += '\n';
      this.configText += '#没有分表策略会自动路由到默认库\n';
      this.configText += 'spring.shardingsphere.sharding.default-data-source-name=' + this.value100 + '_0\n';
      this.configText += '\n';
      this.configText += '# 自定义分库配置策略\n';
      this.configText += 'spring.shardingsphere.sharding.default-database-strategy.standard.sharding-column=cust_no\n';
      this.configText += 'spring.shardingsphere.sharding.default-database-strategy.standard.precise-algorithm-class-name=com.dooleen.common.biz.core.shardingsphere.strategy.MyPreciseDatabaseCustNoShardingAlgorithm\n';
      this.configText += '\n';
      this.configText += '# 自定义分表配置策略\n';
      this.configText += 'spring.shardingsphere.sharding.default-table-strategy.standard.sharding-column=cust_no\n';
      this.configText += 'spring.shardingsphere.sharding.default-table-strategy.standard.precise-algorithm-class-name=com.dooleen.common.biz.core.shardingsphere.strategy.MyPreciseTableCustNoShardingAlgorithm\n';
      this.configText += '\n';
      this.configText += '#定义每张表的路由规则\n';
      //百表参数
      list.forEach(element => {
        this.configText += 'spring.shardingsphere.sharding.tables.' + element.tableName + '.actual-data-nodes=' + this.value100 + '_$->{0..' + id + '}.' + element.tableName + '_$->{0..' + id + '}\n';
      });

      this.configText = headText + this.configText;
    },


    /**
     * 但库配置-查询数据库
     */
    handleGen1Config() {
      if (!this.value100) {
        this.$message({
          customClass: 'zZindex',
          type: 'info',
          message: '请选择库!'
        });
        return false
      }
      this.linkAddress.forEach(element => {
        if (element.label == this.value100) {
          this.databaseLinkAddress = element.value;
        }
      });

      this.reqParams = {
        singleBody: {
          tableSchema: this.value100
        },
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1,
        pageSize: 1000
      }
      //console1.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      querySysToolTablesListPage(this.commonData).then(res => {
        this.configDialogVisible = true;
        this.configText = '';
        this.genConfig(res.data.body.listBody);
      }, error => {
        this.loading = false;
      });
    },
    genConfig(list) {
      var headText = 'spring.shardingsphere.datasource.names=';
      //生成百库配置 this.value100
      var id = 0;
      var tableCnt = 1;
      for (var i = 1; i <= tableCnt; i++) {
        var index = i;
        id = i;
        if (i < tableCnt) {
          headText += 'master' + index + ',';
        }
        else {
          headText += 'master' + index + '\n';
        }
        this.configText += '#master' + index + '\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.type=com.alibaba.druid.pool.DruidDataSource\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.driver-class-name=com.mysql.cj.jdbc.Driver\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.url=jdbc:mysql://' + this.databaseLinkAddress + '/D00' + index + '?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&verifyServerCertificate=false&autoReconnct=true&autoReconnectForPools=true&useInformationSchema=true&allowMultiQueries=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.username=ENC(9tgLVt3eYub3lxf2MN/yAA==)\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.password=ENC(M+7CDg0t6CEEnFfFZCQaX2LuTFecjf8x)\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.initial-size=10\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.min-idle=10\n';
        this.configText += '#spring.shardingsphere.datasource.master' + index + '.max-idle=1000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.max-active=1000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.max-wait=30000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.timeBetweenEvictionRunsMillis=60000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.minEvictableIdleTimeMillis=300000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.validationQuery=SELECT 1 FROM DUAL\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.testWhileIdle=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.testOnBorrow=false\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.testOnReturn=false\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.poolPreparedStatements=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.maxPoolPreparedStatementPerConnectionSize=20\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.filters=stat,wall,log4j\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.connectionProperties=druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.web-stat-filter.enabled=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.web-stat-filter.url-pattern=/*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.deny=192.168.1.73\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.reset-enable=false\n';
        this.configText += '# 合并多个DruidDataSource的监控数据\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.useGlobalDataSourceStat=true\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.logSlowSql=true\n';
        this.configText += '#以下4项，将来上生产环境以后一定要改！！！！！一定要改！！！！！一定要改！！！！！\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.url-pattern=/druid/*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.allow=127.0.0.1,*\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.login-username=admin\n';
        this.configText += 'spring.shardingsphere.datasource.master' + index + '.stat-view-servlet.login-password=admin123\n';
        this.configText += '\n';
        this.configText += '# 读写分离 master' + index + ' 参数\n';
        this.configText += 'spring.shardingsphere.sharding.master-slave-rules.D00' + index + '.master-data-source-name=master' + index + '\n';
        this.configText += 'spring.shardingsphere.sharding.master-slave-rules.D00' + index + '.slave-data-source-names=master' + index + '\n';
        this.configText += '\n';
      }
      this.configText += '# 打印执行的数据库以及语句\n';
      this.configText += 'spring.shardingsphere.props.sql.show = true\n';
      this.configText += 'spring.main.allow-bean-definition-overriding=true\n';
      this.configText += '\n';

      this.configText += '# #shardingjdbc解析上下文和改写后的SQL\n';
      this.configText += 'spring.shardingsphere.props.sql.show=false**\n';
      this.configText += '\n';
      this.configText += '#没有分表策略会自动路由到默认库\n';
      this.configText += 'spring.shardingsphere.sharding.default-data-source-name=D001\n';
      this.configText += '\n';
      this.configText += '# 自定义分库配置策略\n';
      this.configText += 'spring.shardingsphere.sharding.default-database-strategy.complex.sharding-columns=id,tenant_id\n';
      this.configText += 'spring.shardingsphere.sharding.default-database-strategy.complex.algorithm-class-name=com.dooleen.common.biz.core.shardingsphere.strategy.MyDBComplexKeysShardingAlgorithm\n';
      this.configText += '\n';
      this.configText += '\n';
      this.configText += '#定义每张表的路由规则\n';
      //百表参数
      list.forEach(element => {
        this.configText += 'spring.shardingsphere.sharding.tables.' + element.tableName + '.actual-data-nodes=D00$->{1..' + index + '}.' + element.tableName + '\n';
      });

      this.configText = headText + this.configText;
    },

    rowSave(row, done, loading) {
      row.index1 = '[]';
      this.reqParams.singleBody = row;
      this.commonData = reqCommonMsg(this.reqParams)
      saveSysToolTables(this.commonData).then(() => {
        done();
        this.singleBody = {};
        this.onLoad(this.page);
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //console1.log(error);
        loading();
      });
      //console1.log("row = ",row ,loading)
    },
    rowUpdate(row, index, done, loading) {
      this.reqParams.singleBody = row;
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysToolTables(this.commonData).then(() => {
        done();
        this.singleBody = {};
        this.onLoad(this.page);
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //console1.log(error);
        loading();
      });
      //console1.log('loading = ',loading)
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteSysToolTables(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            customClass: 'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => { });
    },
    /**
     * 双击打开详细窗口
     */
    handleRowDBLClick(row, event) {
      this.$refs.crud.rowView(row, row.$index);
    },
    searchReset() {
      this.conditions = [];
      this.singleBody = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.singleBody = params
      this.page.currentPage = 1;
      this.onLoad(this.page);
      done();
    },
    refreshChange() {
      this.singleBody = {};
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.listBody = this.ids;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteSysToolTablesList(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            customClass: 'zZindex',
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        }).catch(() => { });
    },
    /**
     * 拷贝记录
     */
    handleCopy(row) {
      this.$confirm('确定复制数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.loading = true;
          let copyValue = row;
          copyValue.id = '0';
          copyValue.dataSign = '0'
          copyValue.tableName = '拷贝 ' + copyValue.tableName;
          this.reqParams.singleBody = copyValue;
          this.commonData = reqCommonMsg(this.reqParams)
          saveSysToolTables(this.commonData).then(() => {
            this.singleBody = {};
            this.onLoad(this.page);
            this.$message({
              customClass: 'zZindex',
              type: 'success',
              message: '操作成功!'
            });
            this.loading = false;
          }, error => {
            //console1.log(error);
            this.loading = false;
          });
        }).catch(() => { });
    },

    beforeOpen(done, type) {
      this.reqParams = {
        singleBody: {
          id: this.form.id
        }
      }
      let commonData = reqCommonMsg(this.reqParams)
      if (['edit', 'view'].includes(type)) {
        querySysToolTables(commonData).then(res => {
          if (res.data.body.singleBody.index1 != '') {
            res.data.body.singleBody.index1 = JSON.parse(res.data.body.singleBody.index1);
          }
          this.form = res.data.body.singleBody;
        });
      }
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    filterChange(result) {
      this.page.currentPage = 1;
      this.conditions = filterFormat(result)
      this.onLoad(this.page);
    },
    sortChange(val) {
      this.singleBody = {};
      this.orderRules = [val]
      this.onLoad(this.page);
    },
    /**
     * 以下处理数据表字段配置
     */
    // 打开表字段弹框
    handleOpenColumn(row) {
      this.currentRow = row;
      this.drawerDialog = true;
      this.drawerTitle = '数据表定义(' + row.tableName + ')',
        // console.log('==this.currentRow.index1=',this.currentRow.index1);
        // this.currentRow.index1 = JSON.parse(this.currentRow.index1);
        this.cloumnOnLoad();
    },

    cloumnOnLoad(page) {
      const loading = this.$loading({
        lock: true,
        text: '数据加载中...',
        spinner: 'el-icon-loading',
      });
      this.singleBody = {
        tableName: this.currentRow.tableName
      }
      this.orderRules = {
        prop: 'ordinalPosition',
        order: 'ascending'  //descending
      }
      this.reqParams = {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: this.columnPage.currentPage,
        pageSize: this.columnPage.pageSize,
        total: 0
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysToolColumnsListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.columnPage.total = data.total;
        this.columnData = data.listBody;
        this.columnSelectionClear();
        loading.close();
      }, error => {
        loading.close();
      });
    },
    cloumnRefreshChange() {
      this.cloumnOnLoad();
    },


    cloumnAddUpdate(form, index, done, loading) {
      loading();
      this.reqParams.singleBody = form;
      if (!this.reqParams.singleBody.id) {
        this.reqParams.singleBody.id = '0'
      }
      this.commonData = reqCommonMsg(this.reqParams)
      saveOrUpdateSysToolColumns(this.commonData).then(() => {
        done();
        this.cloumnOnLoad();
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '保存成功!'
        });
      }, error => {
        //console1.log(error);
        loading();
      });
      //console1.log('loading = ',loading)
    },

    cloumnRowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteSysToolColumns(this.commonData);
        })
        .then(() => {
          this.cloumnOnLoad();
          this.$message({
            customClass: 'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => { });
    },
    cloumnSaveOrUpdate() {
      // 整理顺序
      this.columnData.forEach((item, index) => {
        this.columnData[index].ordinalPosition = index;
      });
      this.reqParams.listBody = this.columnData;
      this.commonData = reqCommonMsg(this.reqParams)
      saveOrUpdateSysToolColumnsList(this.commonData).then(() => {
        this.cloumnOnLoad();
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '保存成功!'
        });
      }, error => {
        //console1.log(error);
      });
      //console1.log('this.columnData = ',JSON.stringify(this.columnData))
    },
    /**
     * 批量编辑字段
     */
    cloumnBatchEdit() {
      this.columnData.forEach((item, index) => {
        this.columnData[index].$cellEdit = true;
      });
    },
    /**
     * 生成代码
     */
    handleGenerator() {
      this.$confirm('生成代码会覆盖旧代码，请确认数据表基础信息已配置正确，确定要重新生成?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.reqParams = {
          singleBody: this.currentRow,
          head: {
            transSerialNo: 'mgmt'
          }
        }
        this.commonData = reqCommonMsg(this.reqParams)
        generatorCode(this.commonData).then(() => {
          this.$message({
            customClass: 'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }, error => {
          //console1.log(error);
        });
      })
    },

    /**
     * 生成交易代码
     */
    handleTransGenerator() {
      this.$confirm('生成代码会覆盖旧代码，请确认数据表基础信息已配置正确，确定要重新生成?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.reqParams = {
          singleBody: this.currentRow,
          head: {
            transSerialNo: 'tran'
          }
        }
        this.commonData = reqCommonMsg(this.reqParams)
        generatorCode(this.commonData).then(() => {
          this.$message({
            customClass: 'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }, error => {
          //console1.log(error);
        });
      })
    },
    /**
     * 字段选择
     */
    columnSelectionChange(list) {
      this.columnSelectionList = list;
    },
    columnSelectionClear() {
      this.columnSelectionList = [];
      this.$refs.columnCrud.toggleSelection();
    },
    /**
     * 生成MYSQL语句
     */
    generatorSQL() {
      this.columnData.forEach((element, index) => {
        if (element.columnName.trim() == '') {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '第' + (index + 1) + '行字段变量不完整!'
          });
          throw new Error('第' + (index + 1) + '行字段变量不完整!——人工异常');
        }
        else if (element.columnComment.trim() == '') {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '第' + (index + 1) + '行字段名字不完整!'
          });
          throw new Error('第' + (index + 1) + '行字段名字不完整!——人工异常');
        }
      });
      this.sqlDialogVisible = true;
      this.sqlText = genSQL(this.currentRow, this.columnData);
      //console1.log('==generatorSQL =',this.sqlText);
    },
    /**
    * 生成百表语句
    */
    generator100SQL() {
      this.columnData.forEach((element, index) => {
        if (element.columnName.trim() == '') {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '第' + (index + 1) + '行字段变量不完整!'
          });
          throw new Error('第' + (index + 1) + '行字段变量不完整!——人工异常');
        }
        else if (element.columnComment.trim() == '') {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '第' + (index + 1) + '行字段名字不完整!'
          });
          throw new Error('第' + (index + 1) + '行字段名字不完整!——人工异常');
        }
      });
      this.sqlDialogVisible = true;
      var row = JSON.parse(JSON.stringify(this.currentRow));
      this.sqlText = '';
      for (var i = 0; i < 100; i++) {
        row.tableSchema = this.currentRow.tableSchema + '_' + i;
        row.tableName = this.currentRow.tableName + '_' + i;
        this.sqlText += gen100SQL(row, this.columnData) + '\n';
      }
    },

    /**
     * 创建百库语句
     */
    generator100KUSQL() {
      this.configText = '';
      for (var i = 0; i < 100; i++) {
        var tableSchema = this.value100 + '_' + i;
        this.configText += 'CREATE DATABASE ' + tableSchema + ' CHARACTER SET utf8 COLLATE utf8_general_ci;' + '\n';
      }
    },
    /**
   * 生成删除百库语句
   */
    delete100KUSQL() {
      this.configText = '';
      for (var i = 0; i < 100; i++) {
        var tableSchema = this.value100 + '_' + i;
        this.configText += 'DROP DATABASE  ' + tableSchema + ';\n';
      }
    },
    /**
     * 生成MPSQL语句
     */
    generatorPGSQL() {
      this.columnData.forEach((element, index) => {
        if (element.columnName.trim() == '') {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '第' + (index + 1) + '行字段变量不完整!'
          });
          throw new Error('第' + (index + 1) + '行字段变量不完整!——人工异常');
        }
        else if (element.columnComment.trim() == '') {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '第' + (index + 1) + '行字段名字不完整!'
          });
          throw new Error('第' + (index + 1) + '行字段名字不完整!——人工异常');
        }
      });
      this.sqlDialogVisible = true;
      this.sqlText = genPGSQL(this.currentRow, this.columnData);
      //console1.log('==generatorSQL =',this.sqlText);
    },
    /**
     * 生成添加字段SQL语句
     */
    generatorAddSQL() {
      if (this.columnSelectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.sqlDialogVisible = true;
      this.sqlText = genAddColumnSQL(this.currentRow, this.columnSelectionList)
      //console1.log(' == generatorAddSQL == ',this.sqlText)
    },
    /**
     * 生成添加实体语句
     */
    generatorAddEntity() {
      if (this.columnSelectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.sqlDialogVisible = true;
      this.sqlText = genAddColumnEntity(this.currentRow, this.columnSelectionList)
      //console1.log(' == generatorAddSQL == ',this.sqlText)
    },

    /**
     * 生成修改字段SQL语句
     */
    generatorUpdateSQL() {
      if (this.columnSelectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.sqlDialogVisible = true;
      this.sqlText = genUpdateColumnSQL(this.currentRow, this.columnSelectionList)
      //console1.log(' == generatorUpdateSQL == ',this.sqlText)
    },
    /**
     * 生成索引SQL语句
     */
    generatorIndexSQL() {
      console.log('==this.currentRow.index1=', this.currentRow.index1);
      var formatData = [];
      this.indexForm.index1 = [];
      setTimeout(() => {
        this.indexForm.index1 = this.currentRow.index1;
      }, 100);
      this.columnData.forEach(element => {
        formatData.push({
          label: element.columnName + '(' + element.columnComment + ')',
          value: element.columnName
        });
      });
      this.findObject(this.indexOption.column[0].children.column, 'columnName').dicData = formatData;
      this.indexDailog = true;
    },
    /**
     * 更新索引组
     */
    updateIndexColumn() {
      this.currentRow.index1 = this.indexForm.index1;
      this.reqParams.singleBody = this.currentRow;
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysToolTables(this.commonData).then((res) => {
        this.singleBody = {};
        this.currentRow = res.data.body.singleBody;
        this.currentRow.index1 = JSON.parse(this.currentRow.index1);
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '操作成功!'
        });
        this.indexDailog = false;
      }, error => {
        //console1.log(error);
      });

    },


    /**
     * 添加TCC
     */
    addTcc() {
      var formatData = [];
      var decimalData = [];
      this.tccForm.tccIndex = [];
      setTimeout(() => {
        this.tccForm.tccFreezeColumn = this.currentRow.tccFreezeColumn;
        this.tccForm.tccPostColumn = this.currentRow.tccPostColumn;
        this.tccForm.tccIndex = this.currentRow.tccIndex;
      }, 100);
      this.columnData.forEach(element => {
        formatData.push({
          label: element.columnName + '(' + element.columnComment + ')',
          value: element.columnName
        });

        if (element.dataType == 'int2' || element.dataType == 'int4' || element.dataType == 'int8' || element.dataType == 'decimal') {
          decimalData.push({
            label: element.columnName + '(' + element.columnComment + ')',
            value: element.columnName
          })
        }
      });
      this.findObject(this.tccOption.column, 'tccFreezeColumn').dicData = decimalData;
      this.findObject(this.tccOption.column, 'tccPostColumn').dicData = decimalData;
      this.findObject(this.tccOption.column, 'tccIndex').dicData = formatData;
      this.tccDailog = true;
    },

    /**
     * 更新TCC属性
     */
    updateTccColumn() {
      if (this.tccForm.tccFreezeColumn == '' && this.tccForm.tccPostColumn != '') {
        this.$message({
          customClass: 'zZindex',
          type: 'warning',
          message: '冻结资源必输入!'
        });
        return;
      }
      else if (this.tccForm.tccPostColumn != '' && this.tccForm.tccPostColumn == '') {
        this.$message({
          customClass: 'zZindex',
          type: 'warning',
          message: '入账资源必输入!'
        });
        return;
      }
      this.currentRow.tccFreezeColumn = this.tccForm.tccFreezeColumn;
      this.currentRow.tccPostColumn = this.tccForm.tccPostColumn;
      this.currentRow.tccIndex = this.tccForm.tccIndex;
      this.reqParams.singleBody = this.currentRow;
      this.commonData = reqCommonMsg(this.reqParams)
      updateSysToolTables(this.commonData).then((res) => {
        this.singleBody = {};
        this.currentRow = res.data.body.singleBody;
        this.currentRow.index1 = JSON.parse(this.currentRow.index1);
        this.$message({
          customClass: 'zZindex',
          type: 'success',
          message: '操作成功!'
        });
        this.tccDailog = false;
      }, error => {
        //console1.log(error);
      });

    },
    /**
     * 若不能自动生成目录，可以做拷贝创建目录脚本
     */
    openPathDialog() {
      this.pathDialog = true;
      var outPath = '';
      var packagePath = this.currentRow.packageName.replace(/\./g, '/')
      //父工程路径
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/\n';

      //service工程路径
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/' + this.currentRow.projectName + '-impl/src/main/java/' + packagePath + '/entity \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/' + this.currentRow.projectName + '-impl/src/main/java/' + packagePath + '/controller \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/' + this.currentRow.projectName + '-impl/src/main/java/' + packagePath + '/mapper \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/' + this.currentRow.projectName + '-impl/src/main/java/' + packagePath + '/service/impl \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/' + this.currentRow.projectName + '-impl/src/main/resources \n';

      //client工程路径
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/' + this.currentRow.projectName + '-client/src/main/java/' + packagePath + '/client/impl \n';

      //单服务工程
      outPath += '\n\n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/src/main/java/' + packagePath + '/entity \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/src/main/java/' + packagePath + '/controller \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/src/main/java/' + packagePath + '/mapper \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/src/main/java/' + packagePath + '/service/impl \n';
      outPath += 'mkdir -p ' + this.currentRow.backendPath + '/' + this.currentRow.projectName + '/src/main/resources \n';

      //vue 工程路径
      outPath += 'mkdir -p ' + this.currentRow.frontendPath + '/views/' + this.currentRow.moduleName + ' \n';
      outPath += 'mkdir -p ' + this.currentRow.frontendPath + '/api/' + this.currentRow.moduleName + ' \n';
      this.pathText = outPath;
    },

    copyClipboardPath() {
      copyToClipboard(this.pathText, this);
    },
    /**
     * 拷贝到剪贴板
     */
    copyClipboard() {
      copyToClipboard(this.sqlText, this);
    },

    /**
    * 拷贝百库配置到剪贴板
    */
    copyClipboard100Config() {
      copyToClipboard(this.configText, this);
    },
    /**
     * 添加一个字段
     */
    cloumnAddRow(row) {
      // this.$message.success('添加成功！')
      this.$refs.columnCrud.rowCellAdd({
        tableSchema: this.currentRow.tableSchema,
        tableName: this.currentRow.tableName,
        columnComment: row.columnComment || '',
        columnName: row.columnName || '',
        ordinalPosition: 100,
        nullable: true,
        dataType: row.dataType || 'varchar',
        length: row.length || '100',
        decimalLength: row.decimalLength || '0',
        columnKey: false,
        type: 'input',
        search: false,
        searchMultiple: false,
        searchLabelWidth: 100,
        multiple: false,
        dicData: '[]',
        width: '0',
        span: '12',
        excel: true,
        sortable: false,
        required: false,
        showInForm: true,
        message: '请输入内容',
        hide: false,
        value: '',
        overHidden: true
      });
    },
    /**
     * 批量添加变量
     */
    cloumnBatchAdd() {
      this.batchAddColumnDialog = true;
    },
    /**
     * 标准化数据
     */
    handleImport() {
      this.tabLoading = true;
      var dataList = new Array();
      if (this.importDataArea) {
        var lineList = this.importDataArea.split('\n')
        var indx = 0;
        lineList.forEach((element, index) => {
          if (element != null && element.trim() != '') {
            var fieldList = {
              comment: element,
            }
            dataList[indx] = fieldList
            indx++;
            //console1.log('fieldList = ',fieldList)
          }
        });
        //批量写入记录
        this.reqParams.listBody = dataList;
        this.commonData = reqCommonMsg(this.reqParams)
        autoGetSysToolDictFieldList(this.commonData).then(res => {
          this.tabLoading = false;
          this.allFieldData = res.data.body.listBody;
        }, error => {
          //console1.log(error);
          this.tabLoading = false;
        });
        //console1.log('lineList=',dataList)
      }
      else {
        this.tabLoading = false;
        this.$message({
          customClass: 'zZindex',
          type: 'warning',
          message: '数据为空或不正确!'
        });
      }
    },
    /**
     * 批量添加字段到字段列表
     */
    handleBatchImport() {
      if (this.allFieldData.length <= 0) {
        this.$message({
          customClass: 'zZindex',
          type: 'warning',
          message: '字段列表为空!'
        });
        return false;
      }
      this.$confirm('确定要导入字段数据到字段列表?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.batchAddColumnDialog = false;
          this.tabLoading = true;
          this.allFieldData.forEach((element, index) => {
            this.cloumnAddRow(element);
          });
          this.tabLoading = false;
        })
        .then(() => {
          this.$message({
            customClass: 'zZindex',
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => { });
    },
    cancelDrawer() {
      this.drawerDialog = false;
    },
    closeDrawer() {
      this.singleBody.tableName = null
      this.columnData = [];
      this.orderRules = [];
    },
    /**
     * 导出Excel
     */
    exportExcel() {
      this.reqParams = {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1,
        pageSize: 100
      }
      //console1.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      exportSysToolTablesExcel(this.commonData);
    },
    /**
     * 动态获取样式
     */
    tableRowClassName({ row, rowIndex }) {
      if (row.foundFlag === 'field') {
        return 'in-field-row';
      } else if (row.foundFlag === 'root') {
        return 'in-root-row';
      }
      else {
        return '';
      }
    },
    /**
     * 获取树形菜单
     */
    getMenuTree() {
      // 加载树形机构列表
      this.singleBody = {
        parentMenuId: this.userInfo.tenantId + '00000000',
        menuCategory: '1',
        menuLevel: '1'
      }
      //this.$console.log('this.userInfo.tenantId == ',this.singleBody);
      this.reqParams = {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1,
        pageSize: 9999
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysMenuTree(this.commonData).then(res => {
        this.singleBody = {};
        const column = this.findObject(this.menuOption.column, 'parentMenuId');
        column.dicData = [];
        column.dicData = this.deepClone(res.data.body.listBody);
        column.dicData.push({
          id: this.userInfo.tenantId + '00000000',
          name: '根节点'
        })
        //this.$console.log('===tree res.data.body.listBody=====',res.data.body.listBody);
      }, error => {
      });
    },
    /**
   * 获取业务字典参数
   */
    async getSysDict() {
      let dicData = await this.$params.getSysDict('["databaseName","databaseLinkAddress"]');
      this.findObject(this.option.column, 'tableSchema').dicData = dicData.databaseName;
      this.options100 = dicData.databaseName;
      this.linkAddress = dicData.databaseLinkAddress;
      //console.log(dicData.databaseLinkAddress);
    },
  },

  created() {
    this.showColumn = this.$getStore({ name: this.userInfo.userId + 'tableColumn' });
    setTimeout(() => {
      this.getMenuTree();
    }, 500);
    //获取业务字典
    setTimeout(() => {
      this.getSysDict();
    }, 1000);
  },
  watch: {
    showColumn: {
      handler(newValue, oldValue) {
        this.$setStore({ name: this.userInfo.userId + 'tableColumn', content: this.showColumn });
      },
      deep: true
      //this.$setStore({name: this.userInfo.userId +'tableColumn', content: this.showColumn});
    }
  }
};
</script>
<style>
.el-table .in-field-row {
  background: lightgreen !important;
}

.el-table .in-root-row {
  background: powderblue !important;
}
</style>

